package com.zb.controller;

import com.zb.dto.HeapPoint;
import com.zb.dto.TrendPoint;
import com.zb.service.ReportService;
import com.zb.vo.*;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/report")
@Api(value = "ReportController", tags = {"报表控制器"})
public class ReportController {
    @Autowired
    private ReportService reportService;

    /**
     * 折线图
     * @param preViewVO
     * @return
     */
    @PostMapping("/preview")
    public BoardQuotaVO getPreviewData(@RequestBody PreViewVO preViewVO) {
        return reportService.getBoardData(preViewVO.getStart(), preViewVO.getEnd(), preViewVO.getQuotaId(), preViewVO.getDevices(), preViewVO.getType());
    }

    /**
     * 饼图
     * @return
     */
    @GetMapping("/status-list")
    public List<PieVO> getStatusList() {
        return reportService.getStatusList();
    }

    @GetMapping("/device-quota")
    public List<String> getDeviceByQuota(@RequestParam("quotaId") String quotaId) {
        return reportService.getDeviceByQuota(quotaId);
    }


    @GetMapping("/top10")
    public BarVO getTop10(@RequestParam("start") String start,
                          @RequestParam("end") String end) {
        List<HeapPoint> top10Alarm = reportService.getTop10Alarm(start, end);
        BarVO barVO = new BarVO();
        barVO.setXdata(new ArrayList<>());
        barVO.setYdata(new ArrayList<>());
        for (HeapPoint heapPoint : top10Alarm) {
            barVO.getXdata().add(heapPoint.getCount());
            barVO.getYdata().add(heapPoint.getQuotaName() + ":" + heapPoint.getDeviceId());
        }
        return barVO;
    }


    @GetMapping("/trend")
        public LineVO getQuotaTrendCollect(@RequestParam("start") String start,
                                       @RequestParam("end") String end,
                                       @RequestParam("type") Integer type) {
        List<TrendPoint> alarmTrend = reportService.getAlarmTrend(start, end, type);
        LineVO lineVO = new LineVO();
        lineVO.setXdata(new ArrayList<>());
        lineVO.setYdata(new ArrayList<>());
        for (TrendPoint trendPoint : alarmTrend) {
            lineVO.getXdata().add(trendPoint.getTime());
            lineVO.getYdata().add(trendPoint.getCount());
        }
        return lineVO;
    }

}
